home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0145_Anti-Debug unit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  1.9 KB  |  89 lines

  1. Here is an anti-debugging unit I created.  Use AntiOn at the start of
  2. whatever has to be hidden (Password/Key gen) and AntiOff at the end.
  3.  
  4. Actions:
  5. 1) Disable Keyboard
  6. 2) Change interrupts 1&3 {Trace and Breakpoint}
  7. 3) Loop until system time changes. {This will mess up Turbo Debugger}
  8.  
  9. Note:
  10. Interrupts are accessed directly instead of through DOS function 25h,
  11. this will prevent a debugger that takes over all the interrupts from
  12. disabling from still being able to trace/add breakpoints.
  13.  
  14. Right now, intxx is set to INT$20 (Halt program) which will crash the
  15. debugger.  Set it's offset to $10 (INT$04) to just ignore the commands.
  16.  
  17.  
  18. {$A+,B-,D-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S-,T-,V-,X-}
  19.  
  20. unit AntiDbug;
  21.  
  22. interface
  23.  
  24. {Enable anti-debugging technique's, Keyboard will no longer work}
  25. procedure AntiOn;
  26. {Disable anti-debugging technique's}
  27. procedure AntiOff;
  28. {Halts some debuggers (Turbo Debugger), called at unit init;
  29.  Can be called freely}
  30. procedure HaltDebug;
  31.  
  32. implementation
  33.  
  34. var
  35.   {Direct interrupt access}
  36.   Int01: Pointer absolute $0:$004;
  37.   Int03: Pointer absolute $0:$00C;
  38.   IntXX: Pointer absolute $0:$080; {New interrupt, 04=$10, 20=$80}
  39.  
  40.  
  41.   {Saved interrupts}
  42.   SaveInt01,
  43.   SaveInt03: Pointer;
  44.  
  45. procedure Cli; inline($FA); {Clear interrupts}
  46. procedure Sti; inline($FB); {Store interrupts?}
  47.  
  48. procedure HaltDebug; assembler;
  49. asm
  50.   {Wait until clock timer changes}
  51.   push ds
  52.   xor ax, ax
  53.   mov ds, ax
  54.   mov ah, [046Ch]
  55. @@TimerWait:
  56.   mov al, [046Ch]
  57.   cmp al, ah
  58.   je @@TimerWait
  59.   pop ds
  60. end;
  61.  
  62. procedure AntiOn;
  63. begin
  64.   Port[$21] := Port[$21] or $02;
  65.   {Disable interrupts}
  66.   Cli;
  67.   Int03 := IntXX;
  68.   Int01 := IntXX;
  69.   Sti;
  70. end;
  71.  
  72. procedure AntiOff;
  73. begin
  74.   Port[$21] := Port[$21] and $fd;
  75.   {Enable interrupts}
  76.   Cli;
  77.   Int01 := SaveInt01;
  78.   Int03 := SaveInt03;
  79.   Sti;
  80. end;
  81.  
  82. begin
  83.   {Try to mess up debuggers}
  84.   HaltDebug;
  85.   {Save interrutps}
  86.   SaveInt01 := Int01;
  87.   SaveInt03 := Int03;
  88. end.
  89.